package com.vegetable.modules.controller.sys;

import com.vegetable.common.utils.R;
import com.vegetable.modules.controller.AbstractController;
import com.vegetable.modules.entity.sys.SysUserEntity;
import com.vegetable.modules.service.sys.OnlineUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 在线用户相关接口
 *
 * @author vegetable
 */
@RestController
@RequestMapping("/sys/online")
@AllArgsConstructor
@Api(value = "在线用户", tags = "在线用户")
public class OnlineUserController extends AbstractController {
    
    private final OnlineUserService onlineUserService;

    /**
     * 获取在线用户列表
     */
    @GetMapping("/list")
    @ApiOperation(value = "获取在线用户列表", notes = "获取在线用户列表")
    public R list() {
        List<SysUserEntity> onlineUsers = onlineUserService.getOnlineUsers();
        return R.data(onlineUsers);
    }
    
    /**
     * 获取在线用户数量
     */
    @GetMapping("/count")
    @ApiOperation(value = "获取在线用户数量", notes = "获取在线用户数量")
    public R count() {
        List<SysUserEntity> onlineUsers = onlineUserService.getOnlineUsers();
        return R.data(onlineUsers.size());
    }
}